Skip to content

Conversation

@dogramacigokhan
Copy link

@dogramacigokhan dogramacigokhan commented Nov 2, 2020

Issue Description

Fixing payment issue while the app is running in background throws NullReferenceException.

Underlying Reason

Fixing the payment issue triggers a new purchase update from native side with null purchases list when the application is running in background, but the C# side doesn't handle this situation well and throws a NullReferenceException. Actual underlying reason might be triggering the purchase update with null purchases list for this specific case, but considering the annotations in the native code and XML documentations in the C# code, having a null purchases list looks like a valid case and should be handled nonetheless.

Fix

Fix contains three main modifications:

Fix calling a method (size()) on a nullable list coming from native side

In GooglePlayBilling.aar, PurchasesUpdatedListener.onPurchasesUpdated() callback declares a nullable purchases list as follows when it's decompiled:

public interface PurchasesUpdatedListener {
    void onPurchasesUpdated(@NonNull BillingResult var1, @Nullable List<Purchase> var2);
}

but in JniUtils.ParseJavaPurchaseList(), there's no null check before calling the native size() method on it, hence it throws NullReferenceException.

Fix handling empty purchases list

JniUtils.ParseJavaPurchaseList() has following XML doc for the return value:

/// <returns>An IEnumerable of <cref="Purchase"/>. The IEnumerable could be empty.</returns>

but GooglePlayStoreImpl.ParsePurchaseResult() calls First() on the list, hence it throws InvalidOperationException when the list is empty.

Fix enumerating IEnumerable multiple times

GooglePlayStoreImpl.ParsePurchaseResult() enumerates IEnumerable purchases list multiple times (first with _inventory.UpdatePurchaseInventory() call and then with purchasesList.First() call). Added ToList() to evaluate it once and enumerate it multiple times safely.


Related issue: https://issuetracker.google.com/issues/171860953

@google-cla
Copy link

google-cla bot commented Nov 2, 2020

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no label Nov 2, 2020
@dogramacigokhan
Copy link
Author

@googlebot I signed it!

@google-cla
Copy link

google-cla bot commented Nov 2, 2020

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@dogramacigokhan
Copy link
Author

dogramacigokhan commented Nov 2, 2020

Closing because of cla issues. For the correct PR, see: #64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant